home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / insert.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  116 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: insert.c,v 1.7 1996/10/24 15:50:51 aros Exp $
  4.     $Log: insert.c,v $
  5.     Revision 1.7  1996/10/24 15:50:51  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.6  1996/10/21 20:47:53  aros
  9.     Changed struct SysBase to struct ExecBase
  10.  
  11.     Revision 1.5  1996/08/13 13:56:03  digulla
  12.     Replaced AROS_LA by AROS_LHA
  13.     Replaced some AROS_LH*I by AROS_LH*
  14.     Sorted and added includes
  15.  
  16.     Revision 1.4  1996/08/01 17:41:13  digulla
  17.     Added standard header for all files
  18.  
  19.     Desc:
  20.     Lang: english
  21. */
  22. #include "exec_intern.h"
  23.  
  24. /*****************************************************************************
  25.  
  26.     NAME */
  27.     #include <exec/lists.h>
  28.     #include <clib/exec_protos.h>
  29.  
  30.     AROS_LH3I(void, Insert,
  31.  
  32. /*  SYNOPSIS */
  33.     AROS_LHA(struct List *, list, A0),
  34.     AROS_LHA(struct Node *, node, A1),
  35.     AROS_LHA(struct Node *, pred, A2),
  36.  
  37. /*  LOCATION */
  38.     struct ExecBase *, SysBase, 39, Exec)
  39.  
  40. /*  FUNCTION
  41.     Insert Node node after pred in list.
  42.  
  43.     INPUTS
  44.     list - The list to insert the node into
  45.     node - This node is to be inserted
  46.     pred - Insert after this node. If this is NULL, node is inserted
  47.         as the first node (same as AddHead()).
  48.  
  49.     RESULT
  50.  
  51.     NOTES
  52.  
  53.     EXAMPLE
  54.     struct List * list;
  55.     struct Node * pred, * node;
  56.  
  57.     // Insert Node node as second node in list
  58.     pred = GetHead (list);
  59.     Insert (list, node, pred);
  60.  
  61.     BUGS
  62.  
  63.     SEE ALSO
  64.     AddHead(), AddTail(), Enqueue(), RemHead(), Remove(), RemTail(),
  65.     "AROS: Exec Lists".
  66.  
  67.     INTERNALS
  68.  
  69.     HISTORY
  70.     26-08-95    digulla created after EXEC-Routine
  71.     26-10-95    digulla adjusted to new calling scheme
  72.  
  73. ******************************************************************************/
  74. {
  75.     AROS_LIBFUNC_INIT
  76.     assert (node);
  77.     assert (list);
  78.  
  79.     /* If we have a node to insert behind... */
  80.     if (pred)
  81.     {
  82.     /*
  83.         Our successor is the successor of the node we add ourselves
  84.         behind and our predecessor is just the node itself.
  85.     */
  86.     node->ln_Succ = pred->ln_Succ;
  87.     node->ln_Pred = pred;
  88.  
  89.     /*
  90.         We are the predecessor of the successor of our predecessor
  91.         (What ? blblblb... ;) and of out predecessor itself.
  92.         Note that here the sequence is quite important since
  93.         we need ln_Succ in the first expression and change it in
  94.         the second.
  95.     */
  96.     pred->ln_Succ->ln_Pred = node;
  97.     pred->ln_Succ = node;
  98.     }
  99.     else
  100.     {
  101.     /*
  102.         add at the top of the list. I do not use AddHead() here but
  103.         write the code twice for two reasons: 1. The code is small and
  104.         quite prone to errors and 2. If I would call AddHead(), it
  105.         would take almost as long to call the function as the execution
  106.         would take yielding 100% overhead.
  107.     */
  108.     node->ln_Succ           = list->lh_Head;
  109.     node->ln_Pred           = (struct Node *)&list->lh_Head;
  110.     list->lh_Head->ln_Pred = node;
  111.     list->lh_Head           = node;
  112.     }
  113.     AROS_LIBFUNC_EXIT
  114. } /* Insert */
  115.  
  116.